package com.yanmaohu.nikita.scanner;

import com.yanmaohu.nikita.configuration.Configuration;

import java.io.File;

/**
 * @author Bright Lee
 */
public final class SourceCodeStream {

    private final Configuration configuration;
    private final SourceCode sourceCode;
    private int markedIndex;
    private int index;

    public SourceCodeStream(Configuration configuration, File file) {
        this.configuration = configuration;
        this.sourceCode = new SourceCode(file);
    }

    public File getFile() {
        return sourceCode.getFile();
    }

    public SourceCode getCode() {
        return sourceCode;
    }

    public int read() {
        if (index >= sourceCode.length()) {
            return -1;
        }
        return sourceCode.charAt(index++);
    }

    public int index() {
        return index;
    }

    public int mark() {
        return markedIndex = index;
    }

    public void reset() {
        index = markedIndex;
    }

    public void reset(int markedIndex) {
        index = markedIndex;
    }

}
